<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ionglobal.db.*" %>
<%@ page import="com.ionglobal.lib.*" %>
<%@ page import="com.ionglobal.cms.*" %>
<%@ page import="com.ionglobal.misc.*" %>

<%@ include file="../init_include.jsp" %>

<%
	int catid=0;
	int totalpages,pageid=0;
	int pagerows=Page.getPageRows();
	int totalCategorys=0;
	int titleMaxLen=20;
  String ordermode="desc";
  String orderfield="id";
  		
	int check_rst=Permission.accept(dbi,session,request,"sysop","tree","catid","000100000"); 
	if (check_rst!=Permission.CHECK_RST_SUCCESS) {
		dbi.closeAll();
		if (check_rst==Permission.CHECK_RST_DENY)
			response.sendRedirect("../deny.html");
		else
			response.sendRedirect("../index.jsp");
		return;		
	}

	if(request.getParameter("ordermode")!=null)
		ordermode=request.getParameter("ordermode");	
	if(request.getParameter("orderfield")!=null)
		orderfield=request.getParameter("orderfield");		
	
	String a=request.getParameter("catid");
	if(request.getParameter("id")!=null)
		a=request.getParameter("id");
	String str="";
	try {
		catid=Integer.parseInt(a);		
	}	catch(NumberFormatException e) {
		out.println(e+"catId");
		return;
	}
	
	try {
		if (request.getParameter("pageid")!=null)
			pageid=Integer.parseInt(request.getParameter("pageid"));
		else
			pageid=1;
	}	catch(NumberFormatException e) {
		out.println(e+"pageid");
		pageid=1;
	}	
	
	try {
		if (request.getParameter("pagerows")!=null)
			pagerows=Integer.parseInt(request.getParameter("pagerows"));
	} catch(NumberFormatException e) {
		out.println(e+"pagerows");
	}	

	Category cat=new Category(dbi,catid);
	a=cat.getName();
	totalCategorys=Category.getCategorysNum(dbi,catid);
	totalpages = (int)Math.ceil((double)totalCategorys/pagerows);
	if(pageid>totalpages)
		pageid=totalpages;
	if(pageid<=1)
		pageid=1;

	String permissionStr=Permission.getPermissionStr(dbi,session,catid);
	boolean CanCategoryAdd=PermissionItem.Can(permissionStr,PermissionItem.CategoryAdd);
	boolean CanCategoryDel=PermissionItem.Can(permissionStr,PermissionItem.CategoryDel);
	boolean CanCategoryEdit=PermissionItem.Can(permissionStr,PermissionItem.CategoryEdit);
	boolean CanItemBro=PermissionItem.Can(permissionStr,PermissionItem.ItemBro);	
%>	
<html>
<head>
<title><%=Language.getNameByCode("sys.category.manage","Category Manage")%></title>
<meta http-equiv="Content-Type" content="text/html; charset=<%=Language.getHTMLLanguageStr()%>">
<link rel="stylesheet" href="../css.css" type="text/css">
<SCRIPT language=JavaScript1.2 src="../script/Ion_Show.js"></SCRIPT>
<script language="javascript">
<!--

	<% if (CanCategoryAdd) {%>
	function Ion_Add() {
		addIon('vmsSelectFrame.jsp','../sys/category_dj.jsp','<%=Language.getNameByCode("sys.category","Category")%>');
	}
	<%}%>
		
	<% if (CanCategoryDel) {%>
	function Ion_Del() {
		deleteIon('vmsSelectFrame.jsp','../sys/category_delete.jsp','<%=Language.getNameByCode("sys.category","Category")%>');		
	}
	<%}%>
		
	<% if (CanCategoryEdit) {%>	
	function Ion_Edit() {
		editIon('vmsSelectFrame.jsp','../sys/category_dj.jsp','<%=Language.getNameByCode("sys.category","Category")%>');
	}		
	<%}%>
					
	function CopyCategory(hrefstr,actionurl,titlename,name,feature) 
	{
		Copy_Category(hrefstr,actionurl,titlename,name,feature,"bms");
	}

	function ChangeCategory(hrefstr,actionurl,titlename,name,feature) 
	{
		Change_Category(hrefstr,actionurl,titlename,name,feature,"bms");
	}
	
	function showCate()
	{
		location.href="../sys/showCateInfo.jsp?catid="+window.formIon.catid.value;
	}
		
	<% if (CanItemBro) {%>
	function showOther(s)
	{
		location.href=s+"?catid="+window.formIon.catid.value;
	}	
	<% }%>
-->
</script>
</head>

<body bgColor=#d6d3ce leftMargin=0 
style="BORDER-BOTTOM: 0px outset; BORDER-LEFT: 0px outset; BORDER-RIGHT: 0px outset; BORDER-TOP: 0px outset" 
topMargin=0>

<FORM name="formIon" method="post" action="showCateInfo.jsp">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <td class="nagivation" colspan="2"><%=Language.getNameByCode("sys.CurrentPos","Current Position")%>:<% 
    Vector vcpath=Category.getLadder(session,"tree",catid);
		out.print(Category.getFullPath(vcpath));
		%></td>
  </tr>
 	<tr>
    	<td align="left">
    		<%=Language.getNameByCode("sys.category.list","Category List:")%><%=PageStr.getPageHead(totalCategorys,pageid,pagerows,totalpages)%>
    	</td>
     	<td align="right">     	
     		<%=PageStr.PageForm(pageid,totalpages)%><input type="submit" name="Submit" value="go" style="width:0">
      </td>
   	</tr>
	</table>

	<TABLE border=0 cellPadding=0 cellSpacing=1 height="100%" width="100%">
		<input type="hidden" name="catid" value="<%=catid%>">
		<input type="hidden" name="id" value="<%=catid%>">
		<INPUT name="objid" type="hidden">
		<INPUT name="objtext" type="hidden">
		<INPUT name="objflag" type="hidden">
		<INPUT name="actionurl" type="hidden">
		<input type="hidden" name="orderfield" value="<%=orderfield%>">
		<input type="hidden" name="ordermode" value="<%=ordermode%>">
  	<TR>
    <TD>
   <%
   /*
   DictApp da=new DictApp();
   Properties TypeP=da.getDictProperties(dbi,"ProjectType",1,0,"sName","asc");
   Properties StatusP=da.getDictProperties(dbi,"ProjectStatus",1,0,"sName","asc");
   */
    
   Table table=new Table();
   table.setSortMode(ordermode);
   table.setSortField(orderfield);
   table.setSelectionMode("multiple");

   table.addColumn("no","id",0,"center","left","number");
   table.addColumn(Language.getNameByCode("sys.category.id","ID"),"id",30,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.category.name","Name"),"name",250,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.category.owner","Owner"),"ownerid",60,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.category.createdate","Create Date"),"crdate",80,"center","center","text");
   table.addColumn(Language.getNameByCode("sys.category.hot","Hot"),"hot",40,"center","center","text");
   table.addColumn(Language.getNameByCode("sys.category.ordernum","OrderNum"),"ordernum",40,"center","righ","number");
   table.addColumn(Language.getNameByCode("sys.category.code","Code"),"code",40,"center","center","text");
   table.addColumn(Language.getNameByCode("sys.category.module","Module"),"modulecode",40,"center","center","text");

    ArrayList rowsList=new ArrayList();
    try {
     Vector vc=Category.getCategorys(dbi,catid,pageid,pagerows,orderfield,ordermode);
     String rowData="";
     for(int i=0;i<vc.size();i++) {
      Category cr=(Category)vc.get(i);
      rowData=cr.getId()+"|"+cr.getId()+"|"+cr.getName()+"|"+cr.getOwnerId()+"|"+cr.getCrDate()+"|"+(cr.getHot()?Language.getNameByCode("sys.true","true"):Language.getNameByCode("sys.false","false"))+"|"+cr.getOrderNum()+"|"+(cr.getCode()+" ")+"|"+cr.getModulecode();
      rowsList.add(rowData);
     }
    } catch(Exception E) {
    }
  ArrayList menuList=new ArrayList();
  TableMenu tm=null;

	if (CanCategoryEdit) {
		tm=new TableMenu(Language.getNameByCode("sys.category.Edit","Edit Selected Category"),"javascript:Ion_Edit();",false);
		menuList.add(tm);
	}
	if (CanCategoryAdd) {
		tm=new TableMenu(Language.getNameByCode("sys.category.Add","Add New Category"),"JavaScript:Ion_Add();",false);
		menuList.add(tm);
	}
	if (CanCategoryEdit || CanCategoryAdd) {
		tm=new TableMenu(Language.getNameByCode("sys.category.ChangeOrder","Change OrderNum"),"javascript:changeOrder('vmsSelectFrame.jsp','category_showorder.jsp','"+Language.getNameByCode("sys.category","Category")+"');",false);
		menuList.add(tm);
	}
  tm=new TableMenu(Language.getNameByCode("sys.category.SeeChild","View Sub-Category"),"javascript:changeIon('showCateInfo.jsp','"+Language.getNameByCode("sys.category","Category")+"');",true);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.Head.Refresh","Refresh"),"javascript:self.location.reload();",false);
  menuList.add(tm);
	if (CanCategoryDel) {
		tm=new TableMenu("","",true);
		menuList.add(tm);
		tm=new TableMenu(Language.getNameByCode("sys.category.Delete","Delete Selected Categorys"),"javascript:Ion_Del();",false);
		menuList.add(tm);
	}
	tm=new TableMenu("","",true);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.movetocategory","Move Selected Categorys To Another Category"),"javascript:ChangeCategory('vmsSelectFrame.jsp','category_changeCategory.jsp','"+Language.getNameByCode("sys.category","Category")+"');",false);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.copytocategory","Copy Selected Categorys To Another Category"),"javascript:CopyCategory('vmsSelectFrame.jsp','category_copyCategory.jsp','"+Language.getNameByCode("sys.category","Category")+"');",false);
  menuList.add(tm);
	
  table.setTableMenu(menuList);
  table.setRowsList(rowsList);
  TableDB tdb=new TableDB();
  out.print(tdb.draw(table));
  %>

    </TD>
 	</TR>
 	</FORM>
	</TABLE>
</body>
</html>
<%@ include file="../init_free.jsp" %>